<?php 
require 'dbconnect.php';
$username = $_POST['username'];
$password = trim($_POST['password']);
$result = mysql_query("Select * from user where username = '$username'") or die(mysql_error());
if(!$result){
header("Location: index.php");
echo "first query failed";
}
$row = mysql_fetch_array($result);
$storedpw = trim($row['password']);
if($storedpw != trim($password)){
header("Location: index.php");
}
$table = ($row['access'] == 0) ? 'Student' : 'Faculty';
$newvalues = mysql_query("Select * from {$table} where username = '$username'") or die(mysql_error());
session_start();
$values = mysql_fetch_array($newvalues);
//rint_r($values);
$_SESSION['name'] = $values[1];
$_SESSION['id'] = $values[0];
$_SESSION['username'] = $values[5];
$_SESSION['access'] = $values[7];
header("Location: profile.php");
?>